﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Crude.Common
{        
    [DataContract]
    public class ProjectObjectModel : IEquatable<ProjectObjectModel>
    {
        public ProjectObjectModel()
        {
            OutputFiles = new List<OutputFile>();
            Dependencies = new List<ProjectDependency>();
        }

        [DataMember(Order = 0)]
        public string Name { get; set; }

        [DataMember(Order = 1)]
        public string Description {get;set;}

        [DataMember(Order = 2)]
        public string Version { get; set; }

        [DataMember(Order = 3)]
        public string MainOutputFile {get;set;}

        [DataMember(Order = 4)]
        public List<OutputFile> OutputFiles { get; set; }

        [DataMember(Order = 5)]
        public List<ProjectDependency> Dependencies { get; set; }

        public override int GetHashCode()
        {
            int hashCode = Name.GetHashCode() * 27;
            hashCode = (hashCode * 27) + Version.GetHashCode();
            hashCode = (hashCode * 27) + MainOutputFile.GetHashCode();

            return hashCode;
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as ProjectObjectModel);
        }

        public bool Equals(ProjectObjectModel otherPom)
        {
            if (otherPom == null)
            {
                return false;
            }
            else if (!string.Equals(Name, otherPom.Name))
            {
                return false;
            }
            else if (!string.Equals(Description, otherPom.Description))
            {
                return false;
            }
            else if (!string.Equals(Version, otherPom.Version))
            {
                return false;
            }
            else if (!string.Equals(MainOutputFile, otherPom.MainOutputFile))
            {
                return false;
            }
            else if ((Dependencies == null && otherPom.Dependencies != null) ||
                (Dependencies != null && otherPom.Dependencies == null) ||
                 (!Dependencies.SequenceEqual(otherPom.Dependencies)))
            {
                return false;
            }
            else if ((OutputFiles == null && otherPom.OutputFiles != null) ||
                (OutputFiles != null && otherPom.OutputFiles == null) ||
                 (!OutputFiles.SequenceEqual(otherPom.OutputFiles)))
            {
                return false;
            }

            return true;
        }
    }
}
